import java.awt.Canvas;

import javax.swing.JFrame;
public class Main {
	static final int FRAME_DELAY = 20; // 20ms. implies 50fps (1000/20) = 50
	static final JFrame frame = new JFrame();
	public static Canvas gui = new Canvas();
	public static game thegame = new game(); // you just lost
	public static Input input = new Input();
	//-setup sprite bufferer
	static SpriteStorage SpriteStore = new SpriteStorage();
	//timekeeper variables
	public static long[][] timearray = new long[10][5];
	public static String[] timearray2= new String[10];
	public static int times;
	public static long lasttime;
	public static void main(String[] args) {
		if (game.goodpc == true){
			frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			frame.getContentPane().add(gui);
			frame.setSize(1000, 550);
			frame.setResizable(false);
			frame.setVisible(true); // start AWT painting.
			Thread gameThread = new Thread(new RenderEngine(gui));
			//gameThread.setPriority(Thread.MAX_PRIORITY);
			gameThread.start(); // start Game processing.
		}else{
			// IT'S A CRAP PC
			//legacyengine engine1 = new legacyengine(game.resX,game.resY);
			//engine1.run();
			Thread engine1 = new Thread(new legacyengine(game.resX,game.resY));
			engine1.setPriority(Thread.MAX_PRIORITY);
			engine1.start(); // start Game processing.
		}
	}
	public static void timekeeper(String name) {
		times ++;
		timearray2[times] = "\""+name+"\"";
		timearray[times][0] = System.nanoTime();
		timearray[times][1] = (System.nanoTime() - lasttime);
		timearray[times][2] += timearray[times][1];
		timearray[times][3] ++;
		lasttime = System.nanoTime();
	}
	public static void timekeeperreset() {
		times =0;
	}
	public static void timekeeperdisplay() {
		for (int r=0; r<timearray.length; r++){
			if (timearray[r][0] != 0){
				System.out.print("Name:" + timearray2[r] +"\t   The time:" + timearray[r][0] + "\t   Time Taken: " + timearray[r][1] + "\t   Average: " + (timearray[r][2]/timearray[r][3]));
				System.out.println("");
			}
		}
		System.out.println("----------------------------------");
	}
}
